package thread;

import com.sun.source.tree.Tree;

/**
 * Created with IntelliJ IDEA.
 * Description: MyRunnable
 * User: 王圆豪
 * Date: 2025-04-21
 * Time: 21:41
 */
class MyRunnable implements Runnable{

    @Override
    public void run() {
        while(true){
            System.out.println("Hello MyRunnable!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Demo2 {
    public static void main(String[] args) {
        Runnable runnable = new MyRunnable();
        Thread thread = new Thread(runnable);
        thread.start();

        while (true){
            System.out.println("Hello main!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
